package com.dyh.quickdemo.projectReactor;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;

import java.time.Duration;

@SpringBootTest
public class Test1 {

    @Autowired
    DasRepository dasRepository;



    @Test
    public void test(){
        Flux.fromIterable(dasRepository.list()); //会去调用 list "冷" 的流
//        Flux.defer(()->Flux.fromIterable(dasRepository.list())); //"热" 的流


        //Flux.fromIterable(dasRepository.list());
        Disposable disposable = Flux.defer(()->Flux.fromIterable(dasRepository.list()))
                .subscribe(System.out::println);

//        disposable.dispose();

    }

    @Test
    public void test1(){
        Flux.interval(Duration.ofMillis(500))
                .concatWith(Flux.fromIterable(dasRepository.list()))
                .subscribe(System.out::println);

        /*
        2021-07-23 13:42:18.886  INFO 12516 --- [           main] c.d.q.projectReactor.DasRepository       : list
0
1
2
        */

        //保证无限流不结束
        for (;;){

        }
    }

}
